<template>
  <div id="actionNoticeTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="时间范围" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="-"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="活动名称" prop="activityId">
          <el-input
            clearable
            v-model="formInline.activityId"
            placeholder="请输入活动名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="大鹏号" prop="userValue">
          <el-input
            clearable
            v-model="formInline.userValue"
            placeholder="请输入用户大鹏号查询"
          ></el-input>
        </el-form-item>
        <el-form-item label="内容类型" prop="type">
          <el-select v-model="formInline.type" clearable placeholder="请选择">
            <el-option
              v-for="item in contentList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'ActionNoticeSearch',
  msg: '通知管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          activityId: '',
          userValue: '',
          type: '',
          startTime: '', // 开始时间
          endTime: '', // 结束时间
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      // 内容类型
      contentList: [{ dictLabel: '全部', dictValue: '' }],
      rules: {
        activityId: {},
        userValue: {},
        type: {},
        createTime: { type: 'array' }
      }
    }
  },
  mounted() {
    this.getTopSearch()
  },
  methods: {
    // 获取顶部搜索条件
    async getTopSearch() {
      let data = await sysNormalDisable('vote_type', 'contType')
      this.contentList = this.contentList.concat(data)
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  }
}
</script>

<style lang="less">
#actionNoticeTopSearch {
  .el-input {
    &.el-input--suffix {
      width: 182px !important;
    }
  }
}
</style>
